Skip to content

Conversation

@fredrikekre
Copy link
Member

No description provided.

fredrikekre and others added 3 commits September 3, 2024 23:19
This patch removes the method `convert(::Type{String}, ::Kind)` used for
converting kinds to strings and replaces it with the already existing
method of `Base.string`. There are two reason for this: i) the method
causes invalidations when loading the package and ii) `convert` is
called implicitly in e.g. constructors and should therefore typically
only be defined between similar enough types.
This patch removes the method `Base.convert(::Type{Kind}, ::AbstractString)`
and replaces it with a `Kind(::AbstractString)` constructor. The reason
for this is that `convert` is called implicitly in e.g. constructors and
should therefore typically only be defined between similar enough types.
@LilithHafner
Copy link
Member

This seems worth doing to me. converting between Kind and String is too permissive

julia> push!(["a"], K"=")
2-element Vector{String}:
 "a"
 "="

@LilithHafner LilithHafner requested a review from c42f September 11, 2024 16:16
Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems great, thanks :)

@c42f
Copy link
Member

c42f commented Oct 6, 2024

For context, convert() was overridden because the implementation of Kind was originally inspired by Base.@enum.

@LilithHafner
Copy link
Member

Is squash merge okay?

@fredrikekre fredrikekre merged commit 9483de8 into main Oct 6, 2024
@fredrikekre fredrikekre deleted the fe/convert branch October 6, 2024 11:22
@c42f
Copy link
Member

c42f commented Oct 7, 2024

I generally prefer squash merge and I think it's a good default.

Some exceptions where an actual merge commit can be worthwhile:

  • The feature branch has several carefully distinguished changes in their own patches such that keeping them separate makes the history easier to understand.
  • The change was authored by multiple people in distinct patches
  • The merge has nontrivial conflicts with the base branch to the extent that rebasing is very hard and error prone (a very unusual circumstance which mainly happens when multiple large, long lived feature branches interfere. To be avoided! Unlikely to happen in this library.)

@fredrikekre
Copy link
Member Author

For context, convert() was overridden because the implementation of Kind was originally inspired by Base.@enum.

Enums doesn't have any converts like this either though?

c42f pushed a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
…liaLang/JuliaSyntax.jl#500)

* Remove the method `convert(::Type{String}, ::Kind)`

This patch removes the method `convert(::Type{String}, ::Kind)` used for
converting kinds to strings and replaces it with the already existing
method of `Base.string`. There are two reason for this: i) the method
causes invalidations when loading the package and ii) `convert` is
called implicitly in e.g. constructors and should therefore typically
only be defined between similar enough types.

* Remove the method `Base.convert(::Type{Kind}, ::String)`

This patch removes the method `Base.convert(::Type{Kind}, ::AbstractString)`
and replaces it with a `Kind(::AbstractString)` constructor. The reason
for this is that `convert` is called implicitly in e.g. constructors and
should therefore typically only be defined between similar enough types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants